let messagePort=null;
let contextIdentifier=null;

function addContextAndSend(data,destination){
    data.push(contextIdentifier);//添加标识符以标识当前工作者线程
    destination.postMessage(data);//把数据发送到下一个目标
}

self.onmessage=(event)=>{
    console.log('worker',event);
    const {data,ports}=event;
    if(ports.length){
        contextIdentifier=data;
        messagePort=ports[0];
        messagePort.onmessage=({data})=>{
            addContextAndSend(data,self)
        }
    }else{
        addContextAndSend(data,messagePort);
    }
}